#include "stdafx.h"
#include "CppUnitTest.h"

#include "System/Base/Atom.h"
#include "System/Base/Exceptions.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Native::System;

namespace TestNativeSystem
{
    TEST_CLASS(NumericHelper_Tester)
    {
    private:
        void CheckString(
            WSTRING& decimal_output,
            WSTRING& decimal_reference,
            WSTRING& hexadecimal_output,
            WSTRING& hexadecimal_reference)
        {
            Assert::AreEqual(decimal_output, decimal_reference);
            Assert::AreEqual(hexadecimal_output, hexadecimal_reference);
        }

    public:
        TEST_METHOD(Numeric_ParseUnsignalInt8NumericToString)
        {
            uint8_t input = UINT8_MAX;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"255"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"FF"));
        }

        TEST_METHOD(Numeric_ParseSignalInt8NumericToString)
        {
            int8_t input = INT8_MAX;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"127"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"7F"));

            input = INT8_MIN;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"-128"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"80"));
        }

        TEST_METHOD(Numeric_ParseUnsignalInt16NumericToString)
        {
            uint16_t input = UINT16_MAX;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"65535"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"FFFF"));
        }

        TEST_METHOD(Numeric_ParseSignalInt16NumericToString)
        {
            int16_t input = INT16_MAX;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"32767"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"7FFF"));

            input = INT16_MIN;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"-32768"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"8000"));
        }

        TEST_METHOD(Numeric_ParseUnsignalInt32NumericToString)
        {
            uint32_t input = UINT32_MAX;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"4294967295"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"FFFFFFFF"));
        }

        TEST_METHOD(Numeric_ParseSignalInt32NumericToString)
        {
            int32_t input = INT32_MAX;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"2147483647"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"7FFFFFFF"));

            input = INT32_MIN;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"-2147483648"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"80000000"));
        }

        TEST_METHOD(Numeric_ParseUnsignalInt64NumericToString)
        {
            uint64_t input = UINT64_MAX;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"18446744073709551615"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"FFFFFFFFFFFFFFFF"));
        }

        TEST_METHOD(Numeric_ParseSignalInt64NumericToString)
        {
            int64_t input = INT64_MAX;

            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"9223372036854775807"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"7FFFFFFFFFFFFFFF"));

            input = INT64_MIN;
            Assert::AreEqual(UNumeric::ToString(input, BASE_DECIMAL), wstring(L"-9223372036854775808"));
            Assert::AreEqual(UNumeric::ToString(input, BASE_HEXADECIMAL), wstring(L"8000000000000000"));
        }
    };
}